<?php
namespace Home\Controller;
use Think\Controller;

class UserController extends Controller {
    public function login(){
	//$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    $this->display();
	}
	public function order(){
        $this->display();
	}
	public function register(){
		$this->display();
	}
    public function main(){
		$this->display();
	}
    public function completeInf(){
		$this->display();
	}
    public function information(){	
       $type = $this->_post('name');
	   if($type==""){
		   echo "shabi  kongde ";
	   }
	   echo $type;
   }

   public function logout(){
   		session(null);
   		redirect(U("/Home/User/login"), 2, "");
   }

	public function hha(){
		$this->display();
	}

	public function reg(){
		$data['phone'] = I('username');
		$data['password'] = I('password');
		$identify = I('identify');

		if($data['phone'] == '' || $data['password'] == ''){
			$result = array(
				'code' => 203,
				'msg'=> '信息不全'
			);
			echo json_encode($result);
			exit;
		}
		$Dao = M('User');
		$r = $Dao->where('phone = "'.$data['phone'].'"')->select();
		// var_dump($r);
		if($r){
			$result = array(
				'code' => 201,
				'msg'=> '手机号已存在'
			);
		} else {
			$r = $Dao->add($data);
			// var_dump($r);
			if(!$r){
				$result = array(
					'code' => 202,
					'msg'=> '注册失败'
				);
			} else {
				$result = array(
					'code' => 200,
					'msg'=> '注册成功'
				);
				$data['user_id'] = $r;
				session('user', $data);
			}
		}
		echo json_encode($result);
	}

	public function checkLogin() {
		$data['phone'] = I('username');
		$data['password'] = I('password');

		$Dao = M('User');
		$r = $Dao->where($data)->select();

		if($r){
			$result = array(
				'code' => 200,
				'msg' => '登陆成功'
			);
		} else {
			$result = array(
				'code' => 201,
				'msg' => '手机号或密码错误'
			);
		}

		echo json_encode($result);
	}
}